package user_assets_usdt

import (
	"context"
	"strconv"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"
	"github.com/jinzhu/copier"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserUsdtWalletInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 用户USDT钱包信息 - 查询
func NewUserUsdtWalletInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUsdtWalletInfoLogic {
	return &UserUsdtWalletInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserUsdtWalletInfoLogic) UserUsdtWalletInfo(req *types.UserUSDTWalletsInfoRequest) (resp *types.UserUSDTWalletsInfoResponse, err error) {
	info, err := l.svcCtx.AssetsRpc.UserChannel.UserUsdtWalletsInfo(l.ctx, &rpc.UserUsdtWalletsInfoRequest{
		UserId:   req.UserID,
		UsdtType: strconv.FormatInt(req.UsdtType, 10),
		Address:  req.Address,
	})
	var dataList []*types.UserUsdtWalletsInfo

	if err != nil {
		return &types.UserUSDTWalletsInfoResponse{
			UserUSDTWalletsInfoList: dataList,
		}, err
	}
	_ = copier.Copy(&dataList, info.UserUsdtWalletsInfoList)

	return &types.UserUSDTWalletsInfoResponse{
		UserUSDTWalletsInfoList: dataList,
	}, nil
}
